#include "loginwidget.h"
#include "ui_loginwidget.h"

#include <QCryptographicHash>   // 用于使用mdk5来进行加密
#include "databasemanager.h"
#include <QDebug>
#include "log.h"

loginWidget::loginWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::loginWidget)
{
    ui->setupUi(this);


    connect(ui->pushButton_login, &QPushButton::clicked, [this](){
        QString username = ui->lineEdit_user->text();
        QString password = ui->lineEdit_password->text();
        password = this->md5Encrypt(password);
        if (DatabaseManager::getInstance().connectMysql())
        {
            if (DatabaseManager::getInstance().login(username, password))
            {
                qDebug() << "登录成功";


                emit loginSuccess();
            }
        }
    });

}

loginWidget::~loginWidget()
{
    delete ui;
}

QString loginWidget::md5Encrypt(QString password)
{
    QByteArray md5Hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5);
    password = md5Hash.toHex();
    return password;
}

void loginWidget::on_pushButton_cast_clicked()
{

}
